import axios from 'axios'
import router from '../router/router'
import { ElMessage } from 'element-plus'

const request = axios.create({
    baseURL:'http://121.89.205.189:3000/admin'
})

request.interceptors.request.use(req=>{
    req.headers.token = localStorage.getItem('token')
    return req
})


request.interceptors.response.use(res=>{
    if (res.data.code== '10119'){
        // token不存在
        router.push({name:'login'})
    }
    if(res.data.code !='200'){
        ElMessage({
            type:'warning',
            message:res.data.message
        })
    }else{
        return  res.data
    }
})
export default request